# -*- coding: iso-8859-1 -*-
#
#    This is part of Malvinas Argentinas Messenger
#
#    Malvinas Argentinas Messenger is free software; you can redistribute
#    it and/or modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2 of the
#    License, or (at your option) any later version.
#
#    Malvinas Argentinas Messenger is distributed in the hope that it will be
#    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Malvinas Argentinas Messenger; if not, write to the Free
#    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
#    MA  02110-1301  USA

import lstWin, msg, button
import gettext
_ = gettext.gettext

def handleOption(ui, i):
	if i[0] <> -2:
		ui.options_win = 0		
		if i[0] <> -1:
			ui.options_index = -1
			ui.options_list = 0			
		ui.refreshScr()
		# ACCEPT
		if not i[0]:
			# emoticon
			c = ui.winOpt2.list[i[1]]
			n = c.find(" ")
			c = c[:n]
			# For moving padInput.pos of tab
			ui.padArray.wins[ui.padArray.idactive].inputPadPos += len(c)
			# I add char to padInput history of current tab
			ui.padArray.wins[ui.padArray.idactive].set_inputPadText(ui.padArray.wins[ui.padArray.idactive].inputPadText[:ui.padInput.pos] + \
			c + ui.padArray.wins[ui.padArray.idactive].inputPadText[ui.padInput.pos:])
			ui.padInput.clear()
			ui.padInput.addstr(ui.padArray.wins[ui.padArray.idactive].inputPadText)
			ui.padInput.pos = ui.padArray.wins[ui.padArray.idactive].inputPadPos
			ui.padInput.cursPos(ui.padInput.pos)
			ui.padInput.refresh()
		del ui.winOpt2

def showWin(mam):
		list = createEmoticons(mam)
		mam.ui.winOpt2 = lstWin.LstWin(mam, _("INSERT EMOTICON"), '', \
		[button.Button(_("ACCEPT"), 1), button.Button(_("CANCEL"), 0)], mam.ui.maxX * 5 / 7, 
		list)
		mam.ui.winOpt2.list = list

def createEmoticons(mam):
	list = []
	f = open('utils/emoticons', 'r')	
	for line in f:
		list.append(line[:-1])
	f.close
	return list
